# codeing=utf-8

import sys

from PyQt5.QtWidgets import QWidget, QApplication, QToolButton, QMenu, QAction
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtCore import Qt, QUrl


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.init_UI()

    def init_UI(self):
        self.resize(400, 300)
        self.setWindowTitle("工具按钮")

        self.tb = QToolButton(self)
        self.tb.move(100, 100)
        self.tb.setText("支付方式")

        self.tb.setToolTip("选择支付方式")

        self.tb.setIcon(QIcon("源代码/23/icon/bank.ico"))

        self.tb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)  # 设置按钮样式

        # self.tb.setArrowType(Qt.DownArrow)

        # 描述了弹出式菜单与工具按钮一起使用的方式:
        self.tb.setPopupMode(QToolButton.MenuButtonPopup)

        self.menu = QMenu(self)
        self.alipayAct = QAction(QIcon("源代码/23/icon/alipay.ico"), "支付宝支付", self)
        self.wechatAct = QAction(QIcon("源代码/23/icon/wechat.ico"), "微信支付", self)

        self.menu.addAction(self.alipayAct)
        self.menu.addSeparator()
        self.menu.addAction(self.wechatAct)

        self.tb.setMenu(self.menu)

        self.alipayAct.triggered.connect(self.on_click)
        self.wechatAct.triggered.connect(self.on_click)

        self.show()

    def on_click(self):
        if self.sender() == self.alipayAct:
            QDesktopServices.openUrl(QUrl('https://www.alipay.com/'))



if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
